home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Apple Event Objects and You / Apple Event Objects (code) / Headers & Libraries / AEObjects.h next >
Encoding:
C/C++ Source or Header  |  1992-04-08  |  10.4 KB  |  275 lines  |  [TEXT/MPS ]

  1. /*———————————————————————————————————————————————————————————————————————————————————*/
  2. /*
  3.     ©Apple Computer, Inc.  2/21/91
  4.           All Rights Reserved.
  5.  
  6. */
  7.  
  8. #ifndef __AEOBJECTS__
  9. #define __AEOBJECTS__
  10.  
  11. #ifndef __MEMORY__
  12. #include <Memory.h>
  13. #endif
  14.  
  15.  
  16. #ifndef __OSUTILS__
  17. #include <OSUtils.h>
  18. #endif
  19.  
  20. #ifndef __EVENTS__
  21. #include <Events.h>
  22. #endif
  23.  
  24. #ifndef __EPPC__
  25. #include <EPPC.h>
  26. #endif
  27.  
  28. #ifndef __APPLEEVENTS__
  29. #include <AppleEvents.h>
  30. #endif
  31.  
  32.  
  33.  
  34. /* Logical operators: look for them in descriptors of type typeLogicalDescriptor
  35.   with keyword keyAELogicalOperator */
  36. #define kAEAND                        'AND '
  37. #define kAEOR                        'OR  '
  38. #define kAENOT                        'NOT '
  39.  
  40. /* Absolute ordinals: look for them in descriptors of type typeAbsoluteOrdinal.
  41.   Possible use is as keyAEKeyData in an object specifier whose keyAEKeyForm
  42.   field is formAbsolutePosition. */
  43. #define kAEFirst                    'firs'
  44. #define kAELast                        'last'
  45. #define kAEMiddle                    'midd'
  46. #define kAEAny                        'any '
  47. #define kAEAll                        'all '
  48.  
  49. /*  Relative ordinals: look for them in descriptors of type formRelativePosition. */
  50. #define kAENext                        'next'
  51. #define kAEPrevious                    'prev'
  52.  
  53. /********** Keywords for getting fields out of object specifier records **********/
  54. #define keyAEDesiredClass            'want'
  55. #define keyAEContainer                'from'
  56. #define keyAEKeyForm                'form'
  57. #define keyAEKeyData                  'seld'
  58.  
  59.  
  60. /********** Keywords for getting fields out of Range specifier records **********/
  61. #define keyAERangeStart                'star'        /* These are the only two fields in the range desc */
  62. #define keyAERangeStop                'stop'
  63.  
  64. /********** Possible values for the keyAEKeyForm field of an object specifier **********/
  65. /* Remember that this set is an open-ended one.  The OSL makes assumptions about some of them,
  66.   but nothing in the grammar says you can't define your own */
  67. #define formAbsolutePosition         'indx'         /* e.g., 1st, -2nd ( 2nd from end) */
  68. #define formRelativePosition        'rele'         /* next, previous */
  69. #define formTest                    'test'         /* A logical or a comparison */
  70. #define formRange                    'rang'         /* Two arbitrary objects and everything in between */
  71. #define formPropertyID                'prop'         /* Key data is a 4-char property name */
  72. #define formName                    'name'         /* Key data may be of type 'TEXT' */
  73.  
  74. /************** Various relevant types ****************/
  75. /* Some of these tend to be paired with certain of the forms above.  Where this
  76.   is the case comments indicating the form(s) follow. */
  77. #define typeObjectSpecifier          'obj '        /* keyAEContainer will often be one of these */
  78. #define typeObjectBeingExamined     'exmn'        /* Another possible value for keyAEContainer */
  79. #define typeCurrentContainer        'ccnt'        /* Another possible value for keyAEContainer */
  80. #define typeToken                    'toke'        /* Substituted for 'ccnt' before accessor called */
  81.  
  82. #define typeRelativeDescriptor         'rel '        /* formRelativePosition */
  83. #define typeAbsoluteOrdinal         'abso'        /* formAbsolutePosition */
  84. #define typeIndexDescriptor            'inde'        /* formAbsolutePosition */
  85. #define typeRangeDescriptor          'rang'        /* formRange */
  86. #define typeLogicalDescriptor         'logi'        /* formTest is this or typeCompDescriptor */
  87. #define typeCompDescriptor            'cmpd'        /* formTest is this or typeLogicalDescriptor */
  88.  
  89. /************** various relevant keywords ****************/
  90. #define keyAECompOperator            'relo'        /* Relates two terms: '', '<', etc. */
  91. #define keyAELogicalTerms            'term'        /* An AEList of terms to be related by 'logc' below */
  92. #define keyAELogicalOperator        'logc'        /* kAEAND,  kAEOR or kAENOT */
  93. #define keyAEObject1                'obj1'        /* One of two objects in a term must be object specifier */
  94. #define keyAEObject2                'obj2'        /* The other object may be a simple descriptor or obj. spec. */
  95.  
  96.  
  97. /************ Special Handler selectors for OSL Callbacks ***************/
  98. /* You don't need to use these unless you are not using AESetObjectCallbacks. */
  99. #define keyDisposeTokenProc            'xtok'
  100. #define keyAECompareProc              'cmpr'
  101. #define keyAECountProc                  'cont'
  102. #define keyAEMarkTokenProc              'mkid'
  103. #define keyAEMarkProc                  'mark'
  104. #define keyAEAdjustMarksProc          'adjm'
  105. #define keyAEGetErrDescProc          'indc'
  106.  
  107. /************ Error codes ***************/
  108. /* OSL error codes: AEM proper uses up to -1719*/
  109. #define errAEImpossibleRange        -1720         /* A range like 3rd to 2nd, or 1st to all. */
  110. #define errAEWrongNumberArgs        -1721         /* Logical op kAENOT used with other than 1 term */
  111.  
  112. #define errAEAccessorNotFound         -1723         /* Accessor proc matching wantClass and containerType
  113.                                                 ...or wildcards not found */
  114. #define errAENoSuchLogical            -1725          /* Something other than AND, OR, or NOT */
  115. #define errAEBadTestKey                -1726         /* Test is neither typeLogicalDescriptor
  116.                                                 ...nor typeCompDescriptor */
  117. #define errAENotAnObjSpec            -1727          /* Param to AEResolve not of type 'obj ' */
  118. #define errAENoSuchObject            -1728          /* e.g.,: specifier asked for the 3rd, but there are only 2.
  119.                                                 ...Basically, this indicates a run-time resolution error. */
  120. #define errAENegativeCount            -1729         /* CountProc returned negative value */
  121. #define errAEEmptyListContainer        -1730         /* Attempt to pass empty list as container to accessor */
  122.  
  123. /* Possible values for flags parameter to AEResolve.  They're additive */
  124. #define kAEIDoMinimum                0x0000
  125. #define kAEIDoWhose                    0x0001
  126. #define kAEIDoMarking                0x0004
  127.  
  128.  
  129. /* You only care about the constants that follow if you're doing your own whose
  130.   clause resolution */
  131. #define typeWhoseDescriptor            'whos'
  132. #define formWhose                    'whos'
  133. #define typeWhoseRange                'wrng'
  134. #define keyAEWhoseRangeStart        'wstr'
  135. #define keyAEWhoseRangeStop            'wstp'
  136. #define keyAEIndex                    'kidx'
  137. #define keyAETest                    'ktst'
  138.  
  139. struct ccntTokenRecord {        /* used for rewriting tokens in place of 'ccnt' descriptors        */
  140.         DescType tokenClass ;    /* This record is only of interest to those who, when they...    */
  141.         AEDesc token ;            /* ...get ranges as key data in their accessor procs, choose    */
  142.     } ;                            /* ...to resolve them manually rather than call AEResolve again.    */
  143.  
  144. typedef struct ccntTokenRecord ccntTokenRecord, *ccntTokenRecPtr, **ccntTokenRecHandle ;
  145.  
  146. typedef AEDesc *DescPtr, **DescHandle ;
  147.  
  148. /* typedefs providing type checking for procedure pointers */
  149.  
  150. #ifndef THINK_C
  151.     typedef pascal OSErr (*accessorProcPtr) ( DescType desiredClass,
  152.             const AEDesc *container, DescType containerClass, DescType form,
  153.             const AEDesc *selectionData, AEDesc *value, long LongInt ) ;
  154.  
  155.     typedef pascal OSErr (*compareProcPtr)( DescType oper, const AEDesc *obj1,
  156.                 const AEDesc *obj2, Boolean *result ) ;
  157.     typedef pascal OSErr (*countProcPtr)( DescType desiredType, DescType containerClass,
  158.                 const AEDesc *container, long *result ) ;
  159.     typedef pascal OSErr (*disposeTokenProcPtr)( AEDesc *unneededToken ) ;
  160.  
  161.     typedef pascal OSErr (*getMarkTokenProcPtr)( const AEDesc *dContainerToken, DescType containerClass,
  162.                 AEDesc *result ) ;
  163.  
  164.  
  165.     typedef pascal OSErr (*getErrDescProcPtr)( DescPtr *appDescPtr ) ;
  166.  
  167.     /* Note: app is supposed to dispose of dToken after marking */
  168.     typedef pascal OSErr (*markProcPtr)( const AEDesc *dToken, const AEDesc *markToken, long index ) ;
  169.     typedef pascal OSErr (*adjustMarksProcPtr)( long newStart, long newStop, const AEDesc *markToken ) ;
  170. #endif
  171.  
  172. #ifdef THINK_C
  173.     /* THINK C 4.0 doesn't understand the above constructs, so we'll use these instead */
  174.     typedef     ProcPtr    accessorProcPtr;
  175.     typedef     ProcPtr    compareProcPtr;
  176.     typedef     ProcPtr    countProcPtr;
  177.     typedef     ProcPtr    disposeTokenProcPtr;
  178.     typedef     ProcPtr    getMarkTokenProcPtr;
  179.     typedef     ProcPtr    getErrDescProcPtr;
  180.     typedef     ProcPtr    markProcPtr;
  181.     typedef     ProcPtr    adjustMarksProcPtr;
  182.  
  183.     #define const
  184.     /* THINK doesn't understand "const" either... */
  185. #endif
  186.  
  187.  
  188. /*——————————————————————————————— PUBLIC PROCEDURES —————————————————————————————————*/
  189.  
  190.  
  191. pascal OSErr  AEObjectInit(void);    /* THINK_C requires the "void" for prototype checking */
  192. /* Not done by inline, but by direct linking into code.  It sets up the pack
  193.   such that further calls can be via inline */
  194.  
  195. pascal OSErr AESetObjectCallbacks(
  196.                             compareProcPtr        myCompareProc,
  197.                             countProcPtr        myCountProc,
  198.                             disposeTokenProcPtr myDisposeTokenProc,
  199.                             getMarkTokenProcPtr myGetMarkTokenProc,            /* called when mark (below) is true (all 3)*/
  200.                             markProcPtr            myMarkProc,
  201.                             adjustMarksProcPtr    myAdjustMarksProc,
  202.                             getErrDescProcPtr    myGetErrDescProcPtr )
  203. = { 0x303C, 0x0E35, 0xA816 } ;
  204.  
  205.  
  206.  
  207.  
  208. pascal OSErr  AEResolve        (    const AEDesc    *objectSpecifier,
  209.                                 short            callbackFlags,        /* see above for possible values */
  210.                                   AEDesc            *theToken )
  211. = { 0x303C, 0x0536, 0xA816 } ;
  212.  
  213.  
  214. pascal OSErr AEInstallObjectAccessor(
  215.                                 DescType        desiredClass,
  216.                                    DescType        containerType,
  217.                                    accessorProcPtr theAccessor,
  218.                                    long            accessorRefcon,
  219.                                    Boolean            isSysHandler )
  220. = { 0x303C, 0x0937, 0xA816 } ;
  221.  
  222. pascal OSErr AERemoveObjectAccessor(
  223.                                 DescType        desiredClass,
  224.                                 DescType        containerType,
  225.                                 accessorProcPtr theAccessor,
  226.                                 Boolean            isSysHandler )
  227. = { 0x303C, 0x0738, 0xA816 } ;
  228.  
  229. pascal OSErr AEGetObjectAccessor(
  230.                                 DescType         desiredClass,
  231.                                 DescType        containerType,
  232.                                 accessorProcPtr    *accessor,
  233.                                 long            *accessorRefcon,
  234.                                 Boolean            isSysHandler )
  235. = { 0x303C, 0x0939, 0xA816 } ;
  236.  
  237. pascal OSErr AEDisposeToken( AEDesc *theToken )
  238. = { 0x303C, 0x023A, 0xA816 } ;
  239.  
  240. pascal OSErr AECallObjectAccessor(    DescType        desiredClass,
  241.                                     const AEDesc    *containerToken,
  242.                                     DescType        containerClass,
  243.                                     DescType        keyForm,
  244.                                     const AEDesc    *keyData,
  245.                                     AEDesc            *token )
  246. = { 0x303C, 0x0C3B, 0xA816 } ;
  247.  
  248.  
  249.  
  250.  
  251. /*
  252. Here are the interfaces your callback procs must be written to:
  253.  
  254. pascal OSErr MyCompareProc( DescType comparisonOperator, const AEDesc *theObject,
  255.         const AEDesc *descOrObj, Boolean *result ) ;
  256. pascal OSErr MyCountProc( DescType desiredType, DescType containerClass,
  257.             const AEDesc *container, long *result:  ) ;
  258. pascal OSErr MyGetMarkToken( const AEDesc *containerToken, DescType containerClass,
  259.         AEDesc *result ) ;
  260. pascal OSErr MyMark( const AEDesc *theToken, const AEDesc *markToken, long markCount ) ;
  261. pascal OSErr MyAdjustMarks( long newStart, long newStop, const AEDesc *markToken ) ;
  262. pascal OSErr MyMyDisposeToken( AEDesc *unneededToken ) ;
  263. pascal OSErr MyGetErrDesc( DescPtr *appDescPtr ) ;
  264.  
  265. pascal OSErr MyObjectAccessor( DescType desiredClass, const AEDesc *containerToken,
  266.         DescType containerClass, DescType keyForm, const AEDesc *keyData,
  267.         AEDesc *theToken, long *theRefcon ) ;
  268.  
  269. You'll probably want to have a number of these last ones.
  270. A proc that finds a line within a document should be installed with 'line' and 'docu'
  271. as the desiredClass and containerClass fields in the call to AEInstallObjectHandler().
  272. */
  273.  
  274. #endif
  275.